<template>
	<view class="content" @click="changeCheckBox">
		<view class="dot" v-show="flag">
		</view>
	</view>
</template>

<script>
	import {mapMutations} from "vuex"
	export default {
		name:"checkBox",
		props:{
			item:{
				default:null,
				type:Object
			}
		},
		data() {
			return {
				flag:false,
				orderPrice:0
			};
		},
		methods:{
			// ...mapMutations("cart",["setGoodsList"]),
			changeCheckBox(){
				this.flag = !this.flag
				if(this.flag){
				const list = uni.getStorageSync("cartList")
				if(list.toString()===''){
					const a =[]
					a.push(this.item)
					uni.setStorageSync("cartList",a)
				}else{
					for (let good of list) {
						if(good.goods_id===this.item.goods_id)return
						list.push(this.item)
						uni.setStorageSync("cartList",list)
					}
				}
				// console.log(list);
					// uni.setStorageSync("cartList",)
				}else{
					var lists = uni.getStorageSync("cartList")
					for (var i = 0; i < lists.length; i++) {
						if(lists[i].goods_id===this.item.goods_id){
							lists.splice(i,1)
						}
					}
					uni.setStorageSync("cartList",lists)
					
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.content{
		margin-right: 15rpx;
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		border: 1px solid black;
		display: flex;
		align-items: center;
		justify-content: center;
		.dot{
			background-color: #000;
			border-radius:50% ;
			border: 1px solid black;
			height: 30rpx;
			width: 30rpx;
		}
	}
</style>